package com.eicas;

import com.strategy.Context;
import com.strategy.IStrategy;

import java.util.HashMap;
import java.util.Map;

public class Demo1 {
    public static void main(String[] args) {
        //以下代码将被优化
        Map<String,IStrategy> strategyMap = new HashMap<>();
        strategyMap.put("A",new A());
        strategyMap.put("B",new B());
        strategyMap.put("C",new C());
        strategyMap.put("D",new D());

        String param = "D";

        Context context = new Context();
        IStrategy strategy = strategyMap.get(param);
        context.setStrategy(strategy);
        context.strategyMethod();
    }

    private static void common(String param) {
        if("A".equals(param)){
            A a = new A();
            a.sayHello();
        }
        if("B".equals(param)){
            B b = new B();
            b.sayHello();
        }
        if("C".equals(param)){
            C c = new C();
            c.sayHello();
        }
    }
}
